package com.hkts.naturalgasauthentication.security.jwt;

        import lombok.extern.slf4j.Slf4j;
        import org.apache.commons.lang.StringUtils;
        import org.springframework.stereotype.Component;

        import javax.servlet.*;
        import javax.servlet.http.HttpServletRequest;
        import java.io.IOException;

@Component
@Slf4j
public class LoginFilter implements Filter {

    public static ThreadLocal<String> toThreadLocal = new ThreadLocal<>();

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        log.info("login过滤器初始化");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) servletRequest;
        String loginType = req.getParameter("loginType");
        if (StringUtils.isNotBlank(loginType)) {
            toThreadLocal.set(loginType);
            log.info("login过滤器:{}", loginType);
        }
        filterChain.doFilter(servletRequest, servletResponse);
    }
}
